{% extends "base.html" %}
{% load	bootstrap3 %}
{% load i18n %}
{% load static %}
{% block header-css %}




{% endblock %}

{% block  title %}{% trans 'Area List' %}{% endblock %}



{% block page-content %}
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-lg-10">
            <h2>{% trans 'Area List' %}</h2>
            <ol class="breadcrumb">
                <li>
                     <a href="/">{% trans 'Home' %}</a>
                </li>
                <li>
                    <a href="{% url "asset:asset_list" %}">{% trans 'Service Manage' %}</a>
                </li>
                <li class="active">
                    <strong>{% trans 'Area List' %}</strong>
                </li>
            </ol>
        </div>
        <div class="col-lg-2">

        </div>
    </div>
    <div class="wrapper wrapper-content animated fadeInRight   ">
        <div class="row">

            <div class="col-lg-12" id="split-right">

                <div class="ibox float-e-margins">

                    <div class="ibox-title">
                        <h5>{% trans 'Area List' %}</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="#" >{% trans 'Config Option 1' %}</a>
                                </li>
                                <li><a href="#" >{% trans 'Config Option 2' %}</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">

                        <div class="table-responsive">

                            <form id="cha" class="form-horizontal" action="" method="GET">
                                {% csrf_token %}
{#                                <div class="pull-left"><input type="text" class="form-control" name="name" placeholder="{% trans 'Hostname' %}" required></div>#}
{#                                &nbsp;#}
{#                                <button class="btn btn-sm btn-primary" type="submit">{% trans 'Query' %}</button>#}
                                {% ifequal user.level 2 %}
                                <a href="{% url "asset:area_add" %}" class="btn btn-sm btn-primary ">{% trans 'Append' %}</a>

                                <a class="btn btn-sm btn-danger  asset_all_del">{% trans 'Batch Remove' %}</a>
                                {% endifequal %}
                            </form>
                            <form id="del_form_asset_all" class="form-horizontal"
                                  action="" method="post">
                                {% csrf_token %}
                                <table class="table table-striped table-bordered table-hover dataTables-example">
                                    <thead>
                                    <tr>
                                       <th width="20">
                                            <input type="checkbox" id="CheckedAll">
                                        </th>
                                        <th>{% trans 'Area Name' %}</th>
                                        <th>{% trans 'Area Short Name' %}</th>
                                        <th>{% trans 'Action' %}</th>
                                    </tr>
                                    </thead>
                                    <tbody>

                                    {% for   row   in   area_list %}

                                        <tr class="gradeA" id="{{ row.id }}">
                                        <td><input type="checkbox" value="{{ row.id }}" name="id"></td>
                                        <td>{{ row.name }}</td>
                                        <td>{{ row.mini_name }}</td>
                                        <td class="center">
                                            {% ifequal user.level 2 %}
                                            <a class="btn btn-primary  btn-xs" href="{% url 'asset:area_update' pk=row.id %}">{% trans 'Update' %}</a>
                                            <a class="btn btn-danger  btn-xs asset_del">{% trans 'Delete' %}</a>
                                            {% else %}
                                                <a class="btn btn-danger  btn-xs asset_del">{% trans 'No Permission' %}</a>
                                            {% endifequal %}
                                        </td>
                                    </tr>
                                    {% endfor %}
                                    </tbody>

                                </table>
                            </form>


                        </div>

                    </div>


                </div>
            </div>
        </div>
    </div>



{% endblock %}
{% block footer-js %}

<script src="{% static 'js/plugins/dataTables/datatables.min.js' %}"></script>

<script>
    $(document).ready(function(){
        $('.dataTables-example').dataTable().fnDestroy();
        $('.dataTables-example').DataTable({
            pageLength: 25,
            responsive: true,
            dom: '<"html5buttons"B>lTfgitp',
            columnDefs : [ { targets : 0, "orderable" : false } ], "order" : [ [ 1, 'asc' ] ] ,
            buttons: [
                { extend: 'copy'},
                {extend: 'csv'},
                {extend: 'excel', title: 'ExampleFile'},
                {extend: 'pdf', title: 'ExampleFile'},

                {extend: 'print',
                 customize: function (win){
                        $(win.document.body).addClass('white-bg');
                        $(win.document.body).css('font-size', '10px');

                        $(win.document.body).find('table')
                                .addClass('compact')
                                .css('font-size', 'inherit');
                }
                }
            ]

        });

    });
    $(document).on('click', '.asset_del', function () {
        var id = $(this).parent().parent().attr('id');
        swal({
            title: '{% trans 'You Are Sure To Delete' %}',
            text: '{% trans 'You Will Never Recover' %}',
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: '{% trans 'confirm' %}',
            cancelButtonText:'{% trans 'cancel' %}',
            closeOnConfirm: false
        }, function () {
            $.ajax({
                headers: {"X-CSRFToken": '{{ csrf_token }}'},
                url: "{% url 'asset:area_all_del' %}",
                type: 'POST',
                data: {'nid': id},
                success: function (data) {
                    var obj = JSON.parse(data);
                    if (obj.status) {
                        swal({title: '{% trans 'Delete' %}', text: '{% trans 'Deleted Successfully' %}', type: "success"}, function () {
                            window.location.reload();
                        })
                    } else {
                        swal('{% trans 'Delete Error' %}', '{% trans 'Delete Error' %}' + "[ " + obj.error + " ]" + '{% trans 'Error' %}', "error");
                    }
                }
            });


        });

    });

    $(document).on('click', '.asset_all_del', function () {
        swal({
            title: '{% trans 'You Are Sure To Delete' %}',
            text: '{% trans 'You Will Never Recover' %}',
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: '{% trans 'confirm' %}',
            cancelButtonText:'{% trans 'cancel' %}',
            closeOnConfirm: false
        }, function () {
            $.ajax({
                 headers: {"X-CSRFToken": '{{ csrf_token }}'},
                url: "{% url 'asset:area_all_del' %}",
                type: 'POST',
                data: $('#del_form_asset_all').serialize(),
                success: function (data) {
                    var obj = JSON.parse(data);
                    if (obj.status) {
                        swal({title: '{% trans 'Delete' %}', text: '{% trans 'Deleted Successfully' %}', type: "success"}, function () {
                            window.location.reload();
                        })
                    } else {
                        swal('{% trans 'Delete Error' %}', '{% trans 'Delete Error' %}' + "[ " + obj.error + " ]" + '{% trans 'Error' %}', "error");
                    }
                }
            });


        });
    });
</script>

{% endblock %}

{% block footer-js-ajax %}
{% endblock %}